package me.shibor.study.quartz.job;

import java.util.ArrayList;
import java.util.Date;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobKey;
import org.quartz.PersistJobDataAfterExecution;

@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class DumbJob implements Job {

	String jobSays;
	float myFloatValue;
	ArrayList<Date> state;
	String type;

	public DumbJob() {
		System.out.println("DumbJob init()...");
	}

	public void execute(JobExecutionContext context) throws JobExecutionException {
		JobKey key = context.getJobDetail().getKey();

		//JobDataMap dataMap = context.getMergedJobDataMap(); 测试发现这里用MergedJobDataMap不能把修改的数据反写回去
		JobDataMap dataMap = context.getJobDetail().getJobDataMap();
		
		
		
		//String jobSays = dataMap.getString("jobSays");
		float val = dataMap.getFloat("myFloatValue");
		//@SuppressWarnings("unchecked")
		//ArrayList<Date> state = (ArrayList<Date>) dataMap.get("myStateData");
		//String type = dataMap.getString("type");

		//state.add(new Date());

		System.err.println("Instance " + key + " of DumbJob says: " + jobSays + ", and val is: " + val);

		System.out.println("myFloatValue: " + val);
		System.out.println("this.myFloatValue: " + this.myFloatValue);
		
		val = val + 1L;
		dataMap.put("myFloatValue", val);
		
		System.out.println("type: " + type);
		System.out.println("this.type: " + this.type);

	}

	public void setJobSays(String jobSays) {
		System.out.println("setJobSayss");
		this.jobSays = jobSays;
	}

	public void setMyFloatValue(float myFloatValue) {
		System.out.println("setMyFloatValue" + myFloatValue);
		this.myFloatValue = myFloatValue;
	}

	public void setState(ArrayList<Date> state) {
		System.out.println("setState");
		this.state = state;
	}

	public String getType() {
		System.out.println("getType: " + type);
		return type;
	}

	public void setType(String type) {
		System.out.println("setType");
		this.type = type;
	}

}